package com.ruoyi.erpconfig.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erpconfig.domain.JdCompany;
import com.ruoyi.erpconfig.service.IJdCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 金蝶公司配置Controller
 * 
 * @author ruoyi
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/erpconfig/jd_company")
public class JdCompanyController extends BaseController
{
    @Autowired
    private IJdCompanyService jdCompanyService;

    /**
     * 查询金蝶公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:list')")
    @GetMapping("/list")
    public TableDataInfo list(JdCompany jdCompany)
    {
        startPage();
        List<JdCompany> list = jdCompanyService.selectJdCompanyList(jdCompany);
        return getDataTable(list);
    }

    /**
     * 导出金蝶公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:export')")
    @Log(title = "金蝶公司配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JdCompany jdCompany)
    {
        List<JdCompany> list = jdCompanyService.selectJdCompanyList(jdCompany);
        ExcelUtil<JdCompany> util = new ExcelUtil<JdCompany>(JdCompany.class);
        util.exportExcel(response, list, "金蝶公司配置数据");
    }

    /**
     * 获取金蝶公司配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:query')")
    @GetMapping(value = "/{jdCompanyId}")
    public AjaxResult getInfo(@PathVariable("jdCompanyId") Long jdCompanyId)
    {
        return success(jdCompanyService.selectJdCompanyByJdCompanyId(jdCompanyId));
    }

    /**
     * 新增金蝶公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:add')")
    @Log(title = "金蝶公司配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JdCompany jdCompany)
    {
        return toAjax(jdCompanyService.insertJdCompany(jdCompany));
    }

    /**
     * 修改金蝶公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:edit')")
    @Log(title = "金蝶公司配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JdCompany jdCompany)
    {
        return toAjax(jdCompanyService.updateJdCompany(jdCompany));
    }

    /**
     * 删除金蝶公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:jd_company:remove')")
    @Log(title = "金蝶公司配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jdCompanyIds}")
    public AjaxResult remove(@PathVariable Long[] jdCompanyIds)
    {
        return toAjax(jdCompanyService.deleteJdCompanyByJdCompanyIds(jdCompanyIds));
    }
}
